﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyTiemVang.DTO;

namespace QuanLyTiemVang.DAO
{
    class DanhSachKhoanThuDAO
    {
        private static QUANLYTIEMVANGEntities dbContext = new QUANLYTIEMVANGEntities();

        public static void Insert(DANHSACHKHOANTHU dskt)
        {
            dbContext.DANHSACHKHOANTHUs.Add(dskt);
            dbContext.SaveChanges();
        }
        public static List<DANHSACHKHOANTHU> SelectAllDanhSachKhoanThu()
        {
            var query = from d in dbContext.DANHSACHKHOANTHUs
                        select d;

            if (query.ToList().Count == 0)
                return null;

            return query.ToList();
        }

        // tam
        public static DANHSACHKHOANTHU getMaDanhSachKhoanThu(DateTime date)
        {
            DANHSACHKHOANTHU danhsach = new DANHSACHKHOANTHU();

            var query = from ds in dbContext.DANHSACHKHOANTHUs
                        where ds.NgayThu == date
                        select ds;
            if (query.Count() > 0)
            {
                return query.First();
            }
            return null;

        }

        public static void UpdateKhoanThu(DANHSACHKHOANTHU dskt)
        {
            var query = dbContext.DANHSACHKHOANTHUs.Find(dskt.MaDanhSachKhoanThu);
            if (query != null)
            {
                query.TienThuPhieuBanHang = dskt.TienThuPhieuBanHang;
                query.TongTienThu = dskt.TongTienThu;
                dbContext.SaveChanges();
            }
        }
    }
}
